package com.example.smartlearning.controller;


import com.example.smartlearning.service.impl.LessonServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/Smart/Lesson/")
public class LessonController {

    @Resource
    LessonServiceImpl lessonService;

    /**
     * mp自带的获取所有数据方法
     *
     * @return 返回
     */
    @GetMapping("getAllLesson")
    public String getAllLesson() {
        System.out.println(lessonService.getAllLesson());
        return lessonService.getAllLesson();
    }

    /**
     * 获取课程列表并进行分页
     *
     * @param start 开始位置
     * @param limit 数据条数
     * @return 返回
     */
    @GetMapping("getList")
    public String getList(@RequestParam("start") int start, @RequestParam("limit") int limit) {
        System.out.println(lessonService.getList(start, limit));
        return lessonService.getList(start, limit);
    }

    /**
     * 用户点赞接口
     *
     * @param lessonId 课程id
     * @param userId   用户id
     * @return 返回
     */
    @PostMapping("likeCourse")
    public String likeCourse(@RequestParam("lessonId") int lessonId, @RequestParam("userId") int userId) {
        return lessonService.likeCourse(lessonId, userId);
    }

    /**
     * 用户取消点赞接口
     *
     * @param lessonId 课程id
     * @param userId   用户id
     * @return 返回
     */
    @PostMapping("dislikeCourse")
    public String dislikeCourse(@RequestParam("lessonId") int lessonId, @RequestParam("userId") int userId) {
        return lessonService.dislikeCourse(lessonId, userId);
    }

    /**
     * 根据课程id获取课程评价接口
     *
     * @param lessonId 课程id
     * @return 返回
     */
    @GetMapping("selectRemarkByLesson")
    public String selectRemarkByLesson(@RequestParam("lessonId") int lessonId) {
        return lessonService.selectRemarkByLesson(lessonId);
    }

    /**
     * 课程评价点赞接口
     *
     * @param lessonRemarkId 课程id
     * @return 返回
     */
    @PostMapping("agreeRemark")
    public String agreeRemark(@RequestParam("lessonRemarkId") int lessonRemarkId) {
        return lessonService.agreeRemark(lessonRemarkId);
    }

    /**
     * 新增评价接口
     *
     * @param lessonId           课程id
     * @param lessonRemarkText   课程评价
     * @param lessonRemarkUserId 评价用户id
     * @return 返回
     */
    @PostMapping("appearRemark")
    public String appearRemark(
            @RequestParam("lessonId") int lessonId,
            @RequestParam("lessonRemarkText") String lessonRemarkText,
            @RequestParam("lessonRemarkUserId") int lessonRemarkUserId) {
        return lessonService.appearRemark(lessonId, lessonRemarkText, lessonRemarkUserId);
    }

    /**
     * 增加课程接口
     *
     * @param lessonLink    链接
     * @param lessonTitle   标题
     * @param lessonTeacher 教师
     * @param lessonPrice   价格
     * @return 返回
     */
    @PostMapping("addLesson")
    public String addLesson(
            @RequestParam("lessonLink") String lessonLink,
            @RequestParam("lessonTitle") String lessonTitle,
            @RequestParam("lessonTeacher") String lessonTeacher,
            @RequestParam("lessonPrice") String lessonPrice
    ) {
        return lessonService.addLesson(lessonLink, lessonTitle, lessonTeacher, lessonPrice);
    }

    /**
     * 删除课程
     *
     * @param lessonId 传入id
     * @return 返回
     */
    @PostMapping("deleteLesson")
    public String deleteLesson(
            @RequestParam("lessonId") int lessonId
    ) {
        return lessonService.deleteLesson(lessonId);
    }

    /**
     * 修改课程
     *
     * @param lessonId      课程id
     * @param lessonLink    课程链接
     * @param lessonTitle   课程标题
     * @param lessonUpvote  点赞数量
     * @param lessonTeacher 课程老师
     * @param lessonPrice   课程价格
     * @return 返回
     */

    @PostMapping("updateLesson")
    public String updateLesson(
            @RequestParam("lessonId") int lessonId,
            @RequestParam("lessonLink") String lessonLink,
            @RequestParam("lessonTitle") String lessonTitle,
            @RequestParam("lessonUpvote") int lessonUpvote,
            @RequestParam("lessonTeacher") String lessonTeacher,
            @RequestParam("lessonPrice") String lessonPrice
    ) {
        return lessonService.updateLesson(lessonId, lessonLink, lessonTitle, lessonUpvote, lessonTeacher, lessonPrice);
    }
}
